<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;
class UserController extends BaseController {
    
    public function _initialize(){
        $this->tbl = 'user';
        $this->model = D($this->tbl);
        parent::_initialize();
    }

    public function index(){
        /*$data = $this->model->select();
        $this->assign('list',$data);
        //dump($data);
 		$this->display();*/
        parent::index($this->tbl,'zjs_id desc');
    }
    public function view(){
    	$id = I('get.id');

    }
    public function form(){
    	/*$this->display();*/
        parent::form($this->tbl);
    }
    public function add(){
    	/*$data = I('post.');
    	//$data['zjs_email']='iamzjs';
        $data['zjs_photo']='';
        if(!empty($_FILES['zjs_photo']['name'])){
            $data['zjs_photo']=$this->uploadfile('zjs_photo');
        }
               
    	if($this->model->create($data)){
    		$this->model->add();
    		$this->success('创建成功！',U('index'));
    	}
    	else{
    		$this->error($this->model->getError());
    	}*/
        parent::add($this->tbl,'zjs_photo');
    }
    public function mod(){
    	/*$id = I('get.id');
    	$one = $this->model->find($id);
    	//dump($one);exit;
    	$this->assign('one',$one);
    	$this->display();*/
        parent::mod($this->tbl);
    }
    public function update(){
    	$data = I('post.');
    	//$data['hobby']=implode(',', $data['hobby'])
    	//dump($data);exit;  
        if(!empty($_FILES['zjs_photo']['name'])){
            /*$photo = $this->model->where('id='.$data['zjs_id'])->getField('zjs_photo');
            if(is_file(filename)){
                unlink();                
            }
            if(is_file(filename)){
                unlink();                
            }*/
            $data['zjs_photo']=$this->uploadfile('zjs_photo');
        }	
    	if($this->model->create($data)){
    		$this->model->save();
    		$this->success('更新成功！',U('index'));
    	}
    	else{
    		$this->error('更新失败！');
    	}
    }
    public function delete(){
    	//M('user')->delete(I('get.id'));
    	$id = I('get.id');
    	$result = $this->model->delete($id);
    	if($result){
    		$this->success('删除成功',U('index'));
    	}
    	else{
    		$this->error('删除失败');
    		}
    }
    public function search(){
    	$key = I('post.search_key');
    	$sql = "select * from zjs_user where zjs_username like '%".$key."%'";
    	$data = M()->query($sql);
    	//M()->execute($sql);
    	$this->assign('users',$data);
    	$this->display();
    }
    
}